<template>
  <el-dialog :close-on-click-modal='false' v-drag :title="$t('升级订阅设置')" :v-if="dialogVisible" :visible.sync="dialogVisible" width="700px" top="5%" @close='close'>
    <el-form ref="form" label-position="left" :inline="true" :model="record" label-width="210px" :rules="rules" style="margin:0 30px;">
      <el-form-item :label="$t('规则库订阅地址')" prop="subrule">
        <el-input v-emoji v-model="record.subrule" ref="subrule" style="width:600px;" size="small" type="textarea"></el-input>
      </el-form-item>
      <el-form-item :label="$t('引擎订阅地址')" prop="subcore">
        <el-input v-emoji v-model="record.subcore" ref="subcore" style="width:600px;" size="small" type="textarea"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="upgrade" class="updata">{{$t('立即更新')}}</el-button>
      <el-button type="primary" @click="submit" class="del">{{$t('确 定')}}</el-button>
      <el-button @click="close" class="addClose">{{$t('取 消')}}</el-button>
    </span>
  </el-dialog>
</template>
<script>

import { getFirmwareSubscribe, setSubscribe, updateSubscribe } from '@/api/system/update'
export default {
  name: 'uploadSub',
  data () {
    return {
      dialogVisible: false,
      record: {
        subrule: '',
        subcore: ''
      },
      recordCopy: {
        subrule: '',
        subcore: ''
      },
      rules: {
      }
    }
  },
  methods: {
    init () {
      this.dialogVisible = true
      getFirmwareSubscribe().then(res => {
        if (res.status === 0) {
          this.record = res.info[0]
        }
      })
    },
    upgrade () {
      updateSubscribe(this.record).then(res => {
        if (res.status === 0) {
          this.$message({
            message: this.$t('更新成功'),
            type: 'success'
          })
          this.$parent.listData()
          this.close()
        }
      })
      // this.$parent.listData()
      // this.close()
    },
    submit () {
      setSubscribe(this.record).then(res => {
        if (res.status === 0) {
          this.$message({
            message: this.$t('设置成功'),
            type: 'success'
          })
          this.$parent.listData()
          this.close()
        }
      })
    },
    close () {
      this.record = Object.assign({}, this.recordCopy)
      this.dialogVisible = false
    }
  }
}
</script>
